package guowenlong.golf.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.ImageButton;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import guowenlong.golf.R;

/**
 * des   : 描述
 * author: Administrator
 * email : guowenlong20000@gmail.com
 * time  : 2017年03月27日 下午 8:40.
 */

public class AddDialog extends Dialog {

  @BindView(R.id.ib_cancel)
  ImageButton ibCancel;
  @BindView(R.id.tv_youyi)
  TextView tvYouyi;

  public AddDialog(@NonNull Context context) {
    super(context);
  }

  public AddDialog(@NonNull Context context, OnClickListener mClickListener) {
    super(context);
    this.mClickListener = mClickListener;
  }

  public AddDialog(@NonNull Context context,
      @StyleRes int themeResId, OnClickListener mClickListener) {
    super(context, R.style.MyDialog);
    this.mClickListener = mClickListener;
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dialog_add);
    ButterKnife.bind(this);
  }

  @Override
  public void show() {
    super.show();
    /**
     * 设置宽度全屏，要设置在show的后面
     */
    LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.gravity = Gravity.BOTTOM;
    layoutParams.width = LayoutParams.MATCH_PARENT;
    layoutParams.height = LayoutParams.MATCH_PARENT;
    getWindow().getDecorView().setPadding(0, 0, 0, 0);
    getWindow().setAttributes(layoutParams);
  }

  @OnClick({R.id.tv_youyi, R.id.ib_cancel})
  public void onViewClicked(View view) {
    switch (view.getId()) {
      case R.id.tv_youyi:
        if (null != mClickListener) {
          mClickListener.onClickListener();
        }
        dismiss();
        break;
      case R.id.ib_cancel:
        dismiss();
        break;
    }
  }

  private OnClickListener mClickListener;

  public interface OnClickListener {

    void onClickListener();
  }
}
